package run.siyuan.jdk.高并发;

import java.util.concurrent.Semaphore;

/**
 * {@code ClassName:} c
 * {@code Description:} TODO
 * {@code Author:} siyuan
 * {@code Date:} 2023/2/26 21:02
 */
public class c {

    static Semaphore s1 = new Semaphore(1);
    static Semaphore s2 = new Semaphore(1);
    static Semaphore s3 = new Semaphore(1);

    public static void main(String[] args) throws InterruptedException {

        s1.acquire();
        s2.acquire();

        new Thread(() -> {
            try {
                s1.acquire();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(1);
            s2.release();
        }).start();

        new Thread(() -> {
            try {
                s2.acquire();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(2);
            s3.release();
        }).start();

        new Thread(() -> {
            try {
                s3.acquire();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(3);
            s1.release();
        }).start();
    }

}
